/**
   Counts the number of times a character appears in a string.
*/

public class CharCounter
{
   /**
      Returns the number of times that a target character
      appears in a string.
      @param source the input string
      @param ch the character to be counted (a string of length 1)
      @return the number of times the target character
      appears in the source
   */
   public static int countChar(String givestr, char insert)
   {
      int i,s=0;
      int len=givestr.length();
      for(i=0;i<len;i++){
         char m;
         m=givestr.charAt(i);
         if(m==insert){
            s++;
         }
      }
      return s;
   }
   
    public static void main(String[] args)
   {
      String givestr;
      char insert;
      givestr="abracadabra";
      insert='a';
      
      System.out.println("Character appears "+CharCounter.countChar(givestr,insert)+" times.");
   }
}